﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ChineseSchool.BLL;
using ChineseSchool.Models.Hethong;

namespace ChineseSchool.UserControl.ThuNghiem
{
    public partial class News : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack) return;
            lblNews.Text = LoadNewsContent();
        }

        public string LoadNewsContent()
        {
            const string format = "ddd, dd/MM/yyyy h:mm:ss tt";
            var strNews = "";
            var lstNewsType = new B_NewsType().GetAlls();
            if (lstNewsType != null && lstNewsType.Count > 0)
            {
                for (var i = 0; i < lstNewsType.Count; i++)
                {
                    strNews += "<div class=\"ccr-gallery-ttile\">";
                    strNews += "    <span></span>";
                    strNews += "    <p><strong>" + lstNewsType[i].newsTypeName + "</strong></p>";
                    strNews += "</div>";
                    var newsTypeId = lstNewsType[i].newsTypeID;
                    var lstNews = (new B_News()).GetBy_NewsTypeID(newsTypeId);
                    if (lstNews != null && lstNews.Count > 0)
                    {
                        strNews += "<ul class=\"blog-s3\">";
                        for (var j = 0; j < lstNews.Count; j++)
                        {

                            strNews += "<li>";
                            strNews += "    <article>";
                            strNews += "        <figure class=\"blog-thumbnails\">";
                            strNews += "            <img  src=\"" + lstNews[j].imageUrl + "\" title=\"" +
                                                        lstNews[j].title + "\" alt=\"" + lstNews[j].title + "\">";
                            strNews += "        </figure>";
                            strNews += "        <div class=\"blog-text\">";
                            strNews += "            <h4><a href=\"" + Util.MakeLinkNewsDetail(lstNews[j].newsID.ToString(CultureInfo.InvariantCulture), Encode.Uni2KD(lstNews[j].title)) + "\">" + lstNews[j].title + "</a></h4>";
                            strNews += "            <span class=\"post-date\">" + lstNews[j].postDate.ToString(format) + "</span> &nbsp; ";
                            strNews += "            <p>";
                            strNews += "                " + lstNews[j].summary + " ";
                            strNews += "            </p>";
                            strNews += "            <div class=\"meta-data\">";
                            strNews +=
                                "                <a href=\"#\" class=\"like\"><i class=\"fa fa-thumbs-o-up\"></i>08</a>";
                            strNews +=
                                "                <a href=\"#\" class=\"comments\"><i class=\"fa fa-comments-o\"></i>49</a>";
                            strNews += "                <span class=\"read-more\"><a href=\"" +
                                                        Util.MakeLinkNewsDetail(
                                                            lstNews[j].newsID.ToString(CultureInfo.InvariantCulture),
                                                                Encode.Uni2KD(lstNews[j].title)) + "\">Xem Chi Tiết</a></span>";
                            strNews += "            </div>";
                            strNews += "        </div>";
                            strNews += "    </article>";
                            strNews += "</li>";
                        }
                        strNews += "</ul>";
                    }

                    strNews += "<div class=\"clearfix\"></div>";
                    strNews += "<nav class=\"nav-paging pull-center\">";
                    strNews += "    <ul>";
                    strNews += "        <li><a href=\"#pre\"><i class=\"fa fa-chevron-left\"></i></a></li>";
                    strNews += "        <li><a href=\"#\">1</a></li>";
                    strNews += "        <li><a href=\"#\">2</a></li>";
                    strNews += "        <li><span class=\"current\">3</span></li>";
                    strNews += "        <li><a href=\"#\">4</a></li>";
                    strNews += "        <li><a href=\"#\">5</a></li>";
                    strNews += "        <li><a href=\"#next\"><i class=\"fa fa-chevron-right\"></i></a></li>";
                    strNews += "    </ul>";
                    strNews += "</nav>";
                }
            }
            return strNews;
        }
    }
}